package com.aaa.java12;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/15 14:50
 * @description：
 * @modified By：
 * @version:
 */
public class ListTest {
    public static void main(String[] args) {
        List<Student> studentList= new ArrayList<>();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Student student1= new Student();
        student1.setId(100);
        student1.setAge(30);
        student1.setName("张三");
        String date1="1992-12-12";
        Date date = null;
        try {
            date = simpleDateFormat.parse(date1);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        student1.setBirthday(date);
        studentList.add(student1);



        Student student2= new Student();
        student2.setId(101);
        student2.setAge(40);
        student2.setName("张三1");
        String date2="1982-12-12";
        Date date22 = null;
        try {
            date22 = simpleDateFormat.parse(date2);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        student2.setBirthday(date22);
        studentList.add(student2);



        Student student3= new Student();
        student3.setId(103);
        student3.setAge(38);
        student3.setName("张三3");
        String date3="1984-12-12";
        Date date33 = null;
        try {
            date33 = simpleDateFormat.parse(date3);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        student3.setBirthday(date33);
        studentList.add(student3);

        System.out.println("排序之前");

        for (Student student : studentList) {
            System.out.println(student.toString());
        }
        System.out.println("排序之后");
        Collections.sort(studentList);
        for (Student student : studentList) {

            System.out.println(student);
        }
    }
}
